package com.jufanshare.myblog.conf;

import com.jufanshare.myblog.common.mvc.RequestHandlerInterceptor;
import com.jufanshare.myblog.common.mvc.SessionHandlerInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;


/**
 * 作用：
 * 作者：Tiddler
 * 时间：2019/1/27 09：43
 * 类名： MvcConfigurer
 **/
@Configuration
public class MvcConfigurer implements WebMvcConfigurer {
    @Bean
    public RequestHandlerInterceptor getRequestHandlerInterceptor(){
        return new RequestHandlerInterceptor();
    }
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(new SessionHandlerInterceptor()).addPathPatterns("/blog/admin/**");
        /**
         * 此处添加拦截器使用getRequestHandlerInterceptor()，是由于要在拦截器RequestHandlerInterceptor中使用@Autowired private RequestService requestService;
         * 如果直接registry.addInterceptor(new RequestHandlerInterceptor());会出现RequestService空指针
         */
        registry.addInterceptor(getRequestHandlerInterceptor()).addPathPatterns("/**/*.html");
    }
}
